<?php
class Pageley_Util_FileTests extends Pageley_Test_Case {
	
	private $directory;
	
	public function setUp() {
		$this->directory = dirname(__FILE__) . "/";
	}
	
	public function testExists() {
		$file = new Pageley_Util_File($this->directory . "FileTests.php");
		$this->assertTrue($file->exists());
		$file = new Pageley_Util_File($this->directory . "NonExistingTests.php");
		$this->assertFalse($file->exists());
	}
	
	public function testIsDirectory() {
		$system = Pageley_Util_System::getInstance();
		$file = new Pageley_Util_File($this->directory . "FileTests.php");
		$this->assertTrue($file->exists());
		$this->assertFalse($file->isDirectory());
	}
	
	public function testGetName() {
		$file = new Pageley_Util_File($this->directory . "FileTests.php");
		$this->assertEquals("FileTests.php", $file->getName());
	}
	
	public function testIsWritable() {
		$file = new Pageley_Util_File($this->directory . "FileTests.php");
		$this->assertTrue($file->isWritable());
	}
	
	public function testOpenCloseDelete() {
		$directory = new Pageley_Util_Directory("temp");
		if(!$directory->exists()) {
			$directory->createDirectory();
		}
		$file = new Pageley_Util_File("temp/testOpenClose.tmp");
		$this->assertFalse($file->exists());
		$file->open("a");
		$file->close();
		$this->assertTrue($file->exists());
		$file->delete();
		$this->assertFalse($file->exists());
	}
}